/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sport;

import javax.ejb.EJBHome;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import team.BasketballTeam;
import team.BasketballTeam;
import team.FootballTeam;
import team.FootballTeam;
import team.HockeyTeam;
import team.HockeyTeam;
import team.Team;
import team.Team;
import team.TeamHome;
import team.TeamHome;

/**
 *
 * @author denaas
 */
public class TeamHomeFabric {
    public static TeamHome getInstance(Integer sportId) throws NamingException {
        InitialContext ic = new InitialContext();
        Object objRef = null;
        switch (sportId.intValue()) {
            case 1:                
                objRef = ic.lookup("ejb/team/FootballTeam");
                break;
            case 2:                
                objRef = ic.lookup("ejb/team/BasketballTeam");    
                break;
            case 3:                
                objRef = ic.lookup("ejb/team/HockeyTeam");    
                break;
        }
        return (TeamHome)PortableRemoteObject.narrow(objRef, TeamHome.class);
    }
    
    public static TeamHome getInstance(Team team) throws NamingException {
        InitialContext ic = new InitialContext();
        Object objRef = null;
        if (team instanceof FootballTeam) {
            objRef = ic.lookup("ejb/team/FootballTeam");
        } else if (team instanceof BasketballTeam) {
            objRef = ic.lookup("ejb/team/BasketballTeam");
        } else if (team instanceof HockeyTeam) {
            objRef = ic.lookup("ejb/team/HockeyTeam");
        }
        return (TeamHome)PortableRemoteObject.narrow(objRef, TeamHome.class);
    }
}
